package rtprtcp

type Pool struct {
	poolSize int
	pos      int
	buf      []byte
}

// NewPool poolSize: 500 * 1024
func NewPool(poolSize int) *Pool {
	return &Pool{
		buf: make([]byte, poolSize),
	}
}

func (pool *Pool) Get(size int) []byte {
	if size > pool.poolSize {
		return make([]byte, size)
	}

	if pool.poolSize-pool.pos < size {
		pool.pos = 0
		pool.buf = make([]byte, pool.poolSize)
	}

	b := pool.buf[pool.pos : pool.pos+size]
	pool.pos += size
	return b
}
